1 module firecracker_d.models.network_interface;
2 import firecracker_d.models.base_model;
3 import firecracker_d.models.rate_limiter;
4 
5 /***
6 * Defines a network interface.
7 ***/
8 struct NetworkInterface {
9     mixin BaseModel;
10 
11 	/***
12 	* Allow requests to the MicroVM Metadata Service
13 	***/
14 	@serializationKeys("allow_mmds_requests") bool allowMMDSRequests;
15 
16 	/***
17 	* The MAC address presented to the guest operating system for this device
18 	***/
19 	@serializationKeys("guest_mac") string guestMAC;
20 
21 	/***
22 	* The host's interface device name that we should use for networking
23 	*
24 	* Example: tap0, eth0, etc.
25 	***/
26     @serializationRequired 
27 	@serializationKeys("host_dev_name") string hostDevName;
28 
29 	/***
30 	* Required: the Firecracker ID we want to use for this network interface
31 	***/
32     @serializationRequired
33 	@serializationKeys("iface_id") string id;
34 
35 	/***
36 	* Recieve rate limiter, meant to stop network traffic flooding from occuring.
37 	***/
38 	@serializationKeys("rx_rate_limiter") RateLimiter rxRateLimiter;
39 
40 	/***
41 	* Transmit rate limiter, meant to stop network traffic flooding from occuring.
42 	***/
43 	@serializationKeys("tx_rate_limiter") RateLimiter txRateLimiter;
44 
45 	/***
46 	* Create the network interface via the Firecracker API. 
47     * Throws: FirecrackerException on error.
48 	***/
49 
50 	bool put(FirecrackerAPIClient cl) {
51 		Response r = cl.put("/network-interfaces/" ~ id, this.stringify);
52 
53 		if(r.code == 204) {
54 			return true;
55 		}
56 		else {
57 			throwFromResponse(r);
58 			return false;
59 		}
60 
61 	}
62 }
63 
64 /***
65 * Defines a partial network interface structure, used to update the rate limiters for that interface, after microvm start.
66 ***/
67 struct PartialNetworkInterface {
68     mixin BaseModel;
69 
70 	/***
71 	* Required: the Firecracker ID we want to update for this network interface
72 	***/
73     @serializationRequired
74     @serializationKeys("iface_id") string id;
75 
76 	/***
77 	* Recieve rate limiter, meant to stop network traffic flooding from occuring.
78 	***/
79 	@serializationKeys("rx_rate_limiter") RateLimiter rxRateLimiter;
80 
81 	/***
82 	* Transmit rate limiter, meant to stop network traffic flooding from occuring.
83 	***/
84 	@serializationKeys("tx_rate_limiter") RateLimiter txRateLimiter;
85 
86     /***
87     * Update an existing network interface via the Firecracker API. 
88     * Throws: FirecrackerException on error.
89     ***/
90 	bool patch(FirecrackerAPIClient cl) {
91 		Response r = cl.put("/network-interfaces/" ~ id, this.stringify);
92 
93 		if(r.code == 204) {
94 			return true;
95 		}
96 		else {
97 			throwFromResponse(r);
98 			return false;
99 		}
100 
101 	}
102 }
103 
104